package com.chen.controller;

import com.chen.common.Result;

import com.chen.service.IDeptService;
import com.chen.vo.dept.DeptCreateReqVO;
import com.chen.vo.dept.DeptUpdateReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author chen
 * @since 2024-04-10
 */
@RestController
@RequestMapping("/depts")
@Validated
@Tag(name = "01后台管理-部门管理")
public class DeptController {
  @Resource
  private IDeptService deptService;


  @GetMapping
  @Operation(summary = "获取部门列表",description = "用于获取全部的部门信息")
  public Result getDeptList(){
   return deptService.getDeptList();
  }

  @DeleteMapping("/{id}")
  @Operation(summary = "根据id删除部门信息",description = "根据id删除部门信息")
  public Result deleteDeptById(
          @Parameter(name = "id",example = "1",required = true) @PathVariable("id")int id
  ){
    return deptService.deleteDeptById(id);
  }

  @PostMapping
  @Operation(summary = "添加部门",description = "添加部门")
  public Result createDept(@Validated @RequestBody DeptCreateReqVO reqVO){
   return deptService.createDept(reqVO);
  }

  @GetMapping("/{id}")
  @Operation(summary = "根据id查找",description = "根据id查找数据")
  public Result getDeptById(
          @Parameter(name = "id",example = "1",required = true)@PathVariable("id")int id
  ){
    return deptService.getDeptById(id);
  }

  @PutMapping
  @Operation(summary = "修改部门信息",description = "修改部门")
  public Result updateDept(@Validated @RequestBody DeptUpdateReqVO reqVO){
    return deptService.updateDept(reqVO);
  }

}
